function [restL,restR]=bdcorrector(index,n,term,type)

if(exist('funcbij.mat','file'))
    load funcbij;
end
if(exist('funchij.mat','file'))
    load funchij;
end


unimesh=(0:1/n:1)';
h=1/n;

if(strcmp(type,'naive'))
    u0L=u0ex(unimesh(1));
    u0R=u0ex(unimesh(n+1));

    u1L=u1ex(unimesh(1));
    u1R=u1ex(unimesh(n+1));

    u2L=u2ex(unimesh(1));
    u2R=u2ex(unimesh(n+1));

    u3L=u3ex(unimesh(1));
    u3R=u3ex(unimesh(n+1));

    uL=[u0L;u1L;u2L;u3L];
    uR=[u0R;u1R;u2R;u3R];

    bL=zeros(1,term); bR=bL;
    hL=zeros(1,term); hR=hL;
    
    for ii=1:term
        bL(ii)=bij{ii}{index}(unimesh(2));
        bR(ii)=bij{ii}{index}(unimesh(n));
        hL(ii)=hij{ii}{index}(unimesh(2));
        hR(ii)=hij{ii}{index}(unimesh(n));
    end
    restL=-1/h/h*bL*uL(1:term)+1/2/h*hL*uL(1:term);
    restR=-1/h/h*bR*uR(1:term)-1/2/h*hR*uR(1:term);

elseif(strcmp(type,'polychaos'))
    u0L=0; u0R=1; u1L=0; u1R=0; u2L=0; u2R=0; u3L=0; u3R=0;
    uL=[u0L;u1L;u2L;u3L];uR=[u0R;u1R;u2R;u3R];
    bL=zeros(1,term); bR=bL; hL=zeros(1,term); hR=hL;
    for ii=1:term
        bL(ii)=bij{ii}{index}(unimesh(2));
        bR(ii)=bij{ii}{index}(unimesh(n));
        hL(ii)=hij{ii}{index}(unimesh(2));
        hR(ii)=hij{ii}{index}(unimesh(n));
    end
    restL=-1/h/h*bL*uL(1:term)+1/2/h*hL*uL(1:term);
    restR=-1/h/h*bR*uR(1:term)-1/2/h*hR*uR(1:term);
    
end


     
     
     